function A_sort = keep1fringe(AA, D_major, D_market, N_st, id_ist_new, id_ist_old)

AA_m = AA(D_major==1,:);

AA_f = zeros(N_st, size(AA,2));

for mm=1:N_st
    AA_f_mm = AA(D_market==mm & D_major==0,:);
    AA_f(mm,:) = AA_f_mm(1,:); % just keep one row as all rows the same
end

A = [AA_m; AA_f];

% sort the same way as initial data inputs in D
A_sort = zeros(size(A));
for jj=1:size(A,1)
    ind=find(id_ist_new==id_ist_old(jj));
    A_sort(jj,:)=A(ind,:);
end







